<?php
/**
 * 控制器基类
 * User: Lin Hui
 * Date: 2017/5/16
 * Time: 11:46
 */

namespace Admin\Controller;
use Think\Controller;

class BasicController extends Controller
{

    /**
     *非法路由页面
     */
    public function _empty()
    {
        header("HTTP/1.0 404 Not Found");
        $this -> display("Public:denied");
    }

    /**
     * ajax返回
     * @param string $msg 信息
     * @param bool $status 状态
     * @param array $data 数据
     * @param string $redirectUrl 跳转URL
     */
    public function responseAjax($msg = '', $status = false, $data = array(), $redirectUrl = '')
    {
        $this->ajaxReturn(array('msg'=>$msg, 'status'=>$status, 'data'=>$data, 'redirectUrl'=>$redirectUrl), 'json');
    }

    /**
     * 错误页面
     * @param $msg
     */
    public function error($msg)
    {
        if(IS_AJAX) {
            $this->responseAjax($msg);
        }
        $this->assign('msg', $msg);
        $this->display('Public:error');
        exit;
    }

    /**
     * 成功页面
     * @param string $msg
     */
    public function success($msg)
    {
        $this->responseAjax($msg, true);
    }

    /**
     *初始化菜单和面包屑
     */
    public function initMenu()
    {
        $route = MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
        $menu_model = D('menu');
        //面包屑
        $bread_crumb = $menu_model->getBreadCrumbs($route);
        //菜单列表
        $menus = $menu_model->getMenuList();
        return array($menus, $bread_crumb);
    }

}